Add clipping apis to GtkRoundedBox
authorMatthias Clasen <mclasen@redhat.com>
Tue, 2 Dec 2014 13:26:36 +0000 (08:26 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 2 Dec 2014 13:26:36 +0000 (08:26 -0500)
This adds two functions for checking whether an axis-aligned
rectangle is completely outside or inside of a rounded box.
These are not trying to be exact, but fast.

gtk/gtkroundedbox.c
gtk/gtkroundedboxprivate.h

index c89a1fd3543259ca0dc4673cc4ccf5a093cdaca4..2b5ac2120d32e2b938ec8be45de0b38f1b354237 100644 (file)
@@ -536,3 +536,50 @@ _gtk_rounded_box_clip_path (const GtkRoundedBox *box,
                    box->box.width, box->box.height);
 }
 
+gboolean
+_gtk_rounded_box_intersects_rectangle (const GtkRoundedBox *box,
+                                       gdouble              x1,
+                                       gdouble              y1,
+                                       gdouble              x2,
+                                       gdouble              y2)
+{
+  if (x2 < box->box.x ||
+      y2 < box->box.y ||
+      x1 >= box->box.x + box->box.width ||
+      y1 >= box->box.y + box->box.height)
+    return FALSE;
+
+  return TRUE;
+}
+
+gboolean
+_gtk_rounded_box_contains_rectangle (const GtkRoundedBox *box,
+                                     gdouble              x1,
+                                     gdouble              y1,
+                                     gdouble              x2,
+                                     gdouble              y2)
+{
+  if (x1 < box->box.x ||
+      y1 < box->box.y ||
+      x2 >= box->box.x + box->box.width ||
+      y2 >= box->box.y + box->box.width)
+    return FALSE;
+
+  if (x1 < box->box.x + box->corner[GTK_CSS_TOP_LEFT].horizontal &&
+      y1 < box->box.y + box->corner[GTK_CSS_TOP_LEFT].vertical)
+    return FALSE;
+
+  if (x2 > box->box.x + box->box.width - box->corner[GTK_CSS_TOP_RIGHT].horizontal &&
+      y1 < box->box.y + box->corner[GTK_CSS_TOP_RIGHT].vertical)
+    return FALSE;
+
+  if (x2 > box->box.x + box->box.width - box->corner[GTK_CSS_BOTTOM_RIGHT].horizontal &&
+      y2 > box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_RIGHT].vertical)
+    return FALSE;
+
+  if (x1 < box->box.x + box->corner[GTK_CSS_BOTTOM_LEFT].horizontal &&
+      y2 > box->box.y + box->box.height - box->corner[GTK_CSS_BOTTOM_LEFT].vertical)
+    return FALSE;
+
+  return TRUE;
+}
index 483216acc2e4f10f71561e8f634856efc905df72..3f98e20de6f128ca6a2cc8646ba555e1f190ae1e 100644 (file)
@@ -91,6 +91,16 @@ void            _gtk_rounded_box_path_left                      (const GtkRounde
                                                                  cairo_t             *cr);
 void            _gtk_rounded_box_clip_path                      (const GtkRoundedBox *box,
                                                                  cairo_t             *cr);
+gboolean        _gtk_rounded_box_intersects_rectangle           (const GtkRoundedBox *box,
+                                                                 gdouble              x1,
+                                                                 gdouble              y1,
+                                                                 gdouble              x2,
+                                                                 gdouble              y2);
+gboolean        _gtk_rounded_box_contains_rectangle             (const GtkRoundedBox *box,
+                                                                 gdouble              x1,
+                                                                 gdouble              y1,
+                                                                 gdouble              x2,
+                                                                 gdouble              y2);
 
 G_END_DECLS